<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Origami::PDF::LinearParser</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Origami::PDF::LinearParser</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/origami/parsers/pdf/linear_rb.html">
                origami/parsers/pdf/linear.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Origami::Parser
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Create a new <a href="../PDF.html">PDF</a> linear Parser.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000590">parse</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000590" class="method-detail">
        <a name="M000590"></a>

        <div class="method-heading">
          <a href="#M000590" class="method-signature">
          <span class="method-name">parse</span><span class="method-args">(stream)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000590-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000590-source">
<pre>
     <span class="ruby-comment cmt"># File origami/parsers/pdf/linear.rb, line 34</span>
 34:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">stream</span>)
 35:         <span class="ruby-keyword kw">super</span>
 36:         
 37:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:force</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
 38:           <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">skip_until</span>(<span class="ruby-regexp re">/%PDF-/</span>).<span class="ruby-identifier">nil?</span>
 39:           <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">pos</span> <span class="ruby-operator">-</span> <span class="ruby-value">5</span>
 40:         <span class="ruby-keyword kw">end</span>
 41: 
 42:         <span class="ruby-identifier">pdf</span> = <span class="ruby-constant">PDF</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">false</span>)
 43: 
 44:         <span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;...Reading header...&quot;</span>
 45:         <span class="ruby-keyword kw">begin</span>
 46:           <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">header</span> = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">Header</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-ivar">@data</span>)
 47:           <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:callback</span>].<span class="ruby-identifier">call</span>(<span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">header</span>)
 48:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">InvalidHeaderError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
 49:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:ignore_errors</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
 50:             <span class="ruby-identifier">warn</span> <span class="ruby-value str">&quot;PDF header is invalid, ignoring...&quot;</span>
 51:           <span class="ruby-keyword kw">else</span>
 52:             <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
 53:           <span class="ruby-keyword kw">end</span>
 54:         <span class="ruby-keyword kw">end</span>
 55:         
 56:         <span class="ruby-comment cmt">#</span>
 57:         <span class="ruby-comment cmt"># Parse each revision</span>
 58:         <span class="ruby-comment cmt">#</span>
 59:         <span class="ruby-identifier">revision</span> = <span class="ruby-value">0</span>
 60:         <span class="ruby-keyword kw">until</span> <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">eos?</span> <span class="ruby-keyword kw">do</span>
 61:           
 62:           <span class="ruby-keyword kw">begin</span>
 63:             
 64:             <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">add_new_revision</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">zero?</span>
 65:             <span class="ruby-identifier">revision</span> = <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">succ</span>
 66:             
 67:             <span class="ruby-identifier">info</span> <span class="ruby-node">&quot;...Parsing revision #{pdf.revisions.size}...&quot;</span>
 68:             <span class="ruby-identifier">parse_objects</span>(<span class="ruby-identifier">pdf</span>)
 69:             <span class="ruby-identifier">parse_xreftable</span>(<span class="ruby-identifier">pdf</span>)
 70:             <span class="ruby-identifier">parse_trailer</span>(<span class="ruby-identifier">pdf</span>)
 71:             
 72:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">SystemExit</span>
 73:             <span class="ruby-identifier">raise</span>
 74:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
 75:             <span class="ruby-identifier">error</span> <span class="ruby-value str">&quot;Cannot read : &quot;</span> <span class="ruby-operator">+</span> (<span class="ruby-ivar">@data</span>.<span class="ruby-identifier">peek</span>(<span class="ruby-value">10</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;...&quot;</span>).<span class="ruby-identifier">inspect</span>
 76:             <span class="ruby-identifier">error</span> <span class="ruby-value str">&quot;Stopped on exception : &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
 77:             
 78:             <span class="ruby-keyword kw">break</span>
 79:           <span class="ruby-keyword kw">end</span>
 80:           
 81:         <span class="ruby-keyword kw">end</span>
 82: 
 83:         <span class="ruby-identifier">warn</span> <span class="ruby-value str">&quot;This file has been linearized.&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">is_linearized?</span>
 84: 
 85:         <span class="ruby-comment cmt">#</span>
 86:         <span class="ruby-comment cmt"># Decrypt encrypted file contents</span>
 87:         <span class="ruby-comment cmt">#</span>
 88:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">is_encrypted?</span>
 89:           <span class="ruby-identifier">warn</span> <span class="ruby-value str">&quot;This document contains encrypted data!&quot;</span>
 90:         
 91:           <span class="ruby-identifier">passwd</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:password</span>]
 92:           <span class="ruby-keyword kw">begin</span>
 93:             <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">passwd</span>)
 94:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">EncryptionInvalidPasswordError</span>
 95:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">passwd</span>.<span class="ruby-identifier">empty?</span>
 96:               <span class="ruby-identifier">passwd</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:prompt_password</span>].<span class="ruby-identifier">call</span>
 97:               <span class="ruby-keyword kw">retry</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">passwd</span>.<span class="ruby-identifier">empty?</span>
 98:             <span class="ruby-keyword kw">end</span>
 99: 
100:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionInvalidPasswordError</span>
101:           <span class="ruby-keyword kw">end</span>
102:         <span class="ruby-keyword kw">end</span>
103: 
104:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">is_signed?</span>
105:           <span class="ruby-identifier">warn</span> <span class="ruby-value str">&quot;This document has been signed!&quot;</span>
106:         <span class="ruby-keyword kw">end</span>
107: 
108:         <span class="ruby-identifier">pdf</span>
109:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>